﻿<template>
  <a-modal
    title="新增凭证记录"
    :width="900"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item label=" 业务分类" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['classtype']" />
        </a-form-item>
        <a-form-item label=" 单据类型" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 " v-decorator="['pk_busitype']" />
        </a-form-item>
        <a-form-item label=" 接口请求唯一标识，用来确定数据唯一性字段" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入接口请求唯一标识，用来确定数据唯一性字段" v-decorator="['billid']" />
        </a-form-item>
        <a-form-item label=" NC公司编码（his直接带NC公司目录编码）" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入NC公司编码（his直接带NC公司目录编码）" v-decorator="['pk_corp']" />
        </a-form-item>
        <a-form-item label=" 日期" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-date-picker style="width: 100%" placeholder="请选择 日期" v-decorator="['billdate']" @change="onChangebilldate"/>
        </a-form-item>
        <a-form-item label=" 门诊住院项目编码" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 门诊住院项目编码" v-decorator="['projectcode']" />
        </a-form-item>
        <a-form-item label=" 门诊住院项目名称" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 门诊住院项目名称" v-decorator="['projectname']" />
        </a-form-item>
        <a-form-item label=" 科室部门编码" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 科室部门编码" v-decorator="['deptcode']" />
        </a-form-item>
        <a-form-item label=" 科室部门名称" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 科室部门名称" v-decorator="['deptname']" />
        </a-form-item>
        <a-form-item label=" 收款方式编码" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 收款方式编码" v-decorator="['intypecode']" />
        </a-form-item>
        <a-form-item label=" 收款方式名称" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 收款方式名称" v-decorator="['intypename']" />
        </a-form-item>
        <a-form-item label=" 仓库编码" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 仓库编码（根据实际药品采购入库仓库而定）" v-decorator="['storecode']" />
        </a-form-item>
        <a-form-item label="仓库名称" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入仓库名称（根据实际药品采购入库仓库而定）" v-decorator="['storename']" />
        </a-form-item>
        <a-form-item label=" 业务类型" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入业务类型（his系统名称） " v-decorator="['histype']" />
        </a-form-item>
        <a-form-item label="供应商编码" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入供应商编码 " v-decorator="['suppliercode']" />
        </a-form-item>
        <a-form-item label="供应商名称 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入供应商名称 " v-decorator="['suppliername']" />
        </a-form-item>
        <a-form-item label=" 是否生成凭证" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入是否生成凭证" v-decorator="['istovoucher']" />
        </a-form-item>
        <a-form-item label="是否退货(Y,N默认N,负数传Y正数转N) " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入是否退货(Y,N默认N,负数传Y正数转N) " v-decorator="['backmoneyflag']" />
        </a-form-item>
        <a-form-item  label="金额" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入金额" v-decorator="['money']" />
        </a-form-item>
        <a-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入备注" v-decorator="['memo']" />
        </a-form-item>
        <div @show="false">
          <a-form-item  label="自定义项1 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入自定义项1 " v-decorator="['def1']" />
        </a-form-item>
        <a-form-item label="自定义项2 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入自定义项2 " v-decorator="['def2']" />
        </a-form-item>
        <a-form-item label="自定义项3 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 自定义项3 " v-decorator="['def3']" />
        </a-form-item>
        <a-form-item label="自定义项4 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入自定义项4 " v-decorator="['def4']" />
        </a-form-item>
        <a-form-item label="自定义项5" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入自定义项5 " v-decorator="['def5']" />
        </a-form-item>
        <a-form-item label="自定义项6" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 自定义项6 " v-decorator="['def6']" />
        </a-form-item>
        <a-form-item label=" 自定义项7 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 自定义项7 " v-decorator="['def7']" />
        </a-form-item>
        <a-form-item label=" 自定义项8 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 自定义项8 " v-decorator="['def8']" />
        </a-form-item>
        <a-form-item label=" 自定义项9 " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 自定义项9 " v-decorator="['def9']" />
        </a-form-item>
        <a-form-item label=" 自定义项10" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 自定义项10" v-decorator="['def10']" />
        </a-form-item>
        <a-form-item label=" 自定义项11" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 自定义项11" v-decorator="['def11']" />
        </a-form-item>
        <a-form-item label=" 自定义项12" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 自定义项12" v-decorator="['def12']" />
        </a-form-item>
        <a-form-item label=" 自定义项13" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 自定义项13" v-decorator="['def13']" />
        </a-form-item>
        <a-form-item label=" 自定义项14" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 自定义项14" v-decorator="['def14']" />
        </a-form-item>
        <a-form-item label=" 自定义项15" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 自定义项15" v-decorator="['def15']" />
        </a-form-item>
        <a-form-item label=" 自定义项16" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 自定义项16" v-decorator="['def16']" />
        </a-form-item>
        <a-form-item label=" 自定义项17" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入 自定义项17" v-decorator="['def17']" />
        </a-form-item>
        <a-form-item label="自定义项18" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入自定义项18" v-decorator="['def18']" />
        </a-form-item>
        <a-form-item label="自定义项19" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入自定义项19" v-decorator="['def19']" />
        </a-form-item>
        <a-form-item label="自定义项20" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入自定义项20" v-decorator="['def20']" />
        </a-form-item>
        </div>
        
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import {
    VoucherAdd
  } from '@/api/modular/main/VoucherManage'

  export default {
    data () {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 15 }
        },
        billdateDateString: '',
        visible: false,
        confirmLoading: false,
        form: this.$form.createForm(this)
      }
    },
    methods: {
      // 初始化方法
      add (record) {
        this.visible = true
      },
      /**
       * 提交表单
       */
      handleSubmit () {
        const { form: { validateFields } } = this
        this.confirmLoading = true
        validateFields((errors, values) => {
          if (!errors) {
            for (const key in values) {
              if (typeof (values[key]) === 'object') {
                values[key] = JSON.stringify(values[key])
              }
            }
            values.billdate = this.billdateDateString
            VoucherAdd(values).then((res) => {
              if (res.success) {
                this.$message.success('新增成功')
                this.confirmLoading = false
                this.$emit('ok', values)
                this.handleCancel()
              } else {
                this.$message.error('新增失败：' + JSON.stringify(res.message))
              }
            }).finally((res) => {
              this.confirmLoading = false
            })
          } else {
            this.confirmLoading = false
          }
        })
      },
      onChangebilldate(date, dateString) {
        this.billdateDateString = dateString
      },
      handleCancel () {
        this.form.resetFields()
        this.visible = false
      }
    }
  }
</script>
